<template>
  <div class="carousel">
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide">
          <img src="http://dummyimage.com/420x300" alt="">
        </div>
        <div class="swiper-slide">
          <img src="http://dummyimage.com/420x300" alt="">
        </div>
        <div class="swiper-slide">
          <img src="http://dummyimage.com/420x300" alt="">
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>

      <!-- 如果需要导航按钮 -->
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>

      <!-- 如果需要滚动条 -->
      <div class="swiper-scrollbar"></div>
    </div>
  </div>
</template>

<script>
import Swiper from "swiper";
// import "swiper/dist/css/swiper.min.css";
export default {
  data() {
    return {};
  },
  mounted() {
    this.initCarousel();
  },
  methods: {
    initCarousel() {
      var mySwiper = new Swiper(".swiper-container", {
        // direction: "vertical", // 垂直切换选项
        loop: true, // 循环模式选项

        // 如果需要分页器
        pagination: {
          el: ".swiper-pagination"
        },

        // 如果需要前进后退按钮
        navigation: {
          nextEl: ".swiper-button-next",
          prevEl: ".swiper-button-prev"
        },

        // 如果需要滚动条
        // scrollbar: {
        //   el: ".swiper-scrollbar"
        // }
      });
    }
  }
};
</script>

<style lang="less" scpoed>
.carousel {
  @media only screen and (max-width: 768px) {
    .example {
      background: blue;
    }
  }
  @media only screen and (min-width: 768px) {
    .example {
      background: blue;
    }
  }
  @media only screen and (min-width: 992px) {
    .example {
      background: blue;
    }
  }
  img {
    width: 100%;
  }
  .swiper {
    ul {
      padding: 0;
      display: flex;
      li {
        flex: 1;
        p {
          text-align: center;
        }
      }
    }
    .pagination {
      position: relative;
      height: 30px;
      .swiper-pagination {
        position: absolute;
        left: 50%;
        width: 80px;
      }
    }
  }
}
</style>